package com.tff.gmall;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @author Fafa Tuo
 * @version 1.0
 * @date 2021/5/6 21:08
 */
public class RedisUtil {

    private  JedisPool jedisPool;

    public void initPool(String host,int port ,int database){
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        /*poolConfig.setMaxTotal(200);
        poolConfig.setMaxIdle(30);
        poolConfig.setBlockWhenExhausted(true);
        poolConfig.setMaxWaitMillis(10*1000);
        poolConfig.setTestOnBorrow(true);*/
        jedisPool=new JedisPool(poolConfig,host,port,20*1000);
    }

    public Jedis getJedis(){
        Jedis jedis = jedisPool.getResource();
        return jedis;
    }

    public Jedis getRedis(){
        JedisPoolConfig poolConfig = new JedisPoolConfig();

       /* poolConfig.setMaxTotal(2000);
        poolConfig.setMaxIdle(300);
        poolConfig.setBlockWhenExhausted(true);
        poolConfig.setMaxWaitMillis(10*1000);
        poolConfig.setTestOnBorrow(true);*/

        JedisPool jedisPool = new JedisPool(poolConfig,"47.94.204.85",6379);
        Jedis jedis = jedisPool.getResource();
        jedis.auth("123456");
        return jedis;
    }


}
